<?php include $this->templateDir . 'common/header.php'; ?>
<body>
<div class="layui-fluid">
     <div class="layui-row layui-col-space10">
         <div class="layui-card layui-col-md12">
             <div class="layui-card-header">
                    <button class="layui-btn layui-btn-sm" onclick="add()">添加邮箱</button>
             </div>
             <div class="layui-card-body">
                 <table class="layui-table" lay-size="sm">
                     <thead>
                     <tr>
                         <td style="min-width: 50px;">ID</td>
                         <td style="min-width: 160px;">发件人邮箱</td>
                         <td style="min-width: 160px;">发件人昵称</td>
                         <td style="min-width: 160px;">邮箱服务器地址</td>
                         <td style="min-width: 160px;">邮箱协议</td>
                         <td style="min-width: 80px;">端口</td>
                         <td style="min-width:  60px;">是否激活</td>
                         <td  style="min-width: 140px;">操作</td>
                     </tr>
                     </thead>
                     <tbody>
                     <?php foreach ($this->data[0] as $rows) { ?>
                         <tr>
                             <td><?php echo $rows['id']?></td>
                             <td><?php echo $rows['sender_mail']?></td>
                             <td><?php echo $rows['sender_name']?></td>
                             <td><?php echo $rows['host']?></td>
                             <td><?php echo $rows['protocol']?></td>
                             <td><?php echo $rows['port']?></td>
                             <td><?php echo $rows['isactive']=='1'?"<button class='layui-btn layui-btn-xs'>已激活</button>":"<button class='layui-btn layui-btn-primary layui-btn-xs'>未激活</button>";?></td>


                             <td class="layui-table-col-special" align="center">
                                 <div class="layui-btn-group">
                                     <button class="layui-btn layui-btn-normal layui-btn-xs" onclick="edit(<?php echo $rows['id']?>)"><i class="layui-icon layui-icon-edit"></i>编辑</button>
                                     <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del(<?php echo $rows['id']?>)"><i class="layui-icon layui-icon-delete"></i>删除</button>
                                 </div>
                             </td>
                         </tr>
                     <?php  } ?>
                     </tbody>
                 </table>
                 <!--分页-->
                 <div class="layui-table-page" style="margin-bottom: -25px;">
                     <div class=" layui-laypage layui-laypage-default">
                         <a href="<?php echo $this->data[1]->firstPage;?>" class="layui-laypage-first" title="首页">首页</a>
                         <a href="<?php echo $this->data[1]->prePage;?>" class="layui-laypage-prev">上一页</a>
                         <?php
                         foreach($this->data[1]->listPage as $k => $v){
                             if($k == $this->data[1]->currentPage){
                                 echo "<span class='layui-laypage-curr'><em class='layui-laypage-em'></em><em>".$k."</em></span>" ;
                             }else{
                                 echo ' <a href="'.$v.'" data-page="'.$k.'">'.$k.'</a>';
                             }
                         }
                         ?>
                         <a href="<?php echo $this->data[1]->nextPage;?>" class="layui-laypage-next" >下一页</a>
                         <a href="<?php echo $this->data[1]->lastPage;?>" class="layui-laypage-last" title="尾页">尾页</a>
                         <span class="layui-laypage-count">共 <?php echo $this->data['count']?> 条</span>
                     </div>
                 </div>
             </div>

         </div>
     </div>
</div>
<script>
    layui.use(['table','layer' ,'jquery' ],function () {
        var table = layui.table;
            layer  = layui.layer;
            $ = layui.jquery;

    });
    function add() {
        layer.open({
            content: "<?php echo u('email','add');?>",
            title: "新增邮箱",
            area: ['60%', '100%'],
            type: 2,
            offset  : 'rb',//右侧抽屉效果
            maxmin: true,
            shadeClose: true
        });
    }
    function edit(id) {
        layer.open({
            content:  "<?php echo PG_SROOT;?>email/edit/" + id,
            title: "编辑角色",
            area: ['50%', '100%'],
            type: 2,
            offset  : 'rb',//右侧抽屉效果
            maxmin: true,
            shadeClose: true
        });
    }
    function del(id) {
        layer.confirm("确定删除邮箱吗?", {icon: 3, title: '提示'},
            function (index) {// 确定回调
                //关闭窗口
                layer.close(index);
                //后台真实删除
                $.ajax({
                    url:"<?php echo u('email','del')?>"
                    ,dataType:"json"
                    ,type:"post"
                    ,data:{'id':id}
                    ,success:function(res){
                        if(res.status == "ok"){
                            layer.msg(  res.data,{icon:6,time:1000} );
                            setTimeout(function(){parent.window.location.reload();},1000);
                        }else{
                            layer.msg(res.data,{icon:7});
                        }
                    }
                });
            }, function (index) {//取消回调
                layer.close(index);
            }
        );
    }
</script>
</body>
</html>